import service from '../require/request';

/**
 * 获取留学地区选项
 * @returns Promise<string[]> 留学地区选项列表
 */
export const getStudyAreas = async (): Promise<string[]> => {
    try {
        // 获取当前登录用户ID
        const uid = localStorage.getItem('uid') || '';
        
        // 发送请求并等待响应
        const apiData = await service.post<string[], string[]>(
            '/b/sme/cdc/career/student_mgt/detail/recommend_info/area/search',
            { uid }
        );

        return apiData;
    } catch (error) {
        console.error('获取留学地区选项失败:', error);
        throw error;
    }
};

/**
 * 获取本科专业选项
 * @returns Promise<string[]> 本科专业选项列表
 */
export const getMajors = async (): Promise<string[]> => {
    try {
        // 获取当前登录用户ID
        const uid = localStorage.getItem('uid') || '';
        
        // 发送请求并等待响应
        const apiData = await service.post<string[], string[]>(
            '/b/sme/cdc/career/student_mgt/detail/recommend_info/major/search',
            { uid }
        );

        return apiData;
    } catch (error) {
        console.error('获取本科专业选项失败:', error);
        throw error;
    }
};

/**
 * 获取留学项目选项
 * @param queryKey 查询关键字
 * @returns Promise<string[]> 留学项目选项列表
 */
export const getPrograms = async (queryKey: string): Promise<string[]> => {
    try {
        // 获取当前登录用户ID
        const uid = localStorage.getItem('uid') || '';
        
        // 发送请求并等待响应
        const apiData = await service.post<string[], string[]>(
            '/b/sme/cdc/career/student_mgt/detail/recommend_info/program/search',
            { 
                uid,
                query_key: queryKey
            }
        );

        return apiData;
    } catch (error) {
        console.error('获取留学项目选项失败:', error);
        throw error;
    }
};

/**
 * 查询推荐学校
 * @param params 查询参数
 * @returns Promise<string[]> 推荐学校列表
 */
export interface SearchSchoolsParams {
    cgpa: string;
    area: string[];
    major: string;
    program: string;
}

export const searchSchools = async (params: SearchSchoolsParams): Promise<string[]> => {
    try {
        // 获取当前登录用户ID
        const uid = localStorage.getItem('uid') || '';
        
        // 发送请求并等待响应
        const apiData = await service.post<string[], string[]>(
            '/b/sme/cdc/career/student_mgt/detail/recommend_info/search',
            { 
                uid,
                ...params
            }
        );

        return apiData;
    } catch (error) {
        console.error('查询推荐学校失败:', error);
        throw error;
    }
};
